package com.zhanggm.ry.rys2.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.zhanggm.ry.rys2.entity.Dept;
import com.zhanggm.ry.rys2.entity.User;
import com.zhanggm.ry.rys2.feign.S1FeignApi;
import com.zhanggm.ry.rys2.mapper.UserMapper;
import com.zhanggm.ry.rys2.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author zhanggm
 * @since 2023-04-23
 */
@RestController
@RequestMapping("/s2/user")
public class UserController extends BaseController {

    @Autowired
    private IUserService userService;

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private S1FeignApi s1FeignApi;

    @GetMapping("list")
    public AjaxResult list(User user) {

        User userInfo = userMapper.getUserByUsername("ry");
        logger.info(userInfo.toString());



        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(user.getNickName() != null, User::getNickName, user.getNickName());

        List<User> list = userService.list(queryWrapper);
        list.forEach(u->{
            R<Dept> r = s1FeignApi.getById(userInfo.getDeptId());
            if (r.getCode() == 200) {
                logger.info("部门信息：{}",r.getData());
                u.setDept(r.getData());
            }
        });
        return AjaxResult.success(list);
    }

}
